import { wxRequest } from '../../utils/server.js';
const _wxRequest = new wxRequest();
const app = getApp()
const WxParse = require('../../wxParse/wxParse.js');
Page({
  data: {
    imgUrl: app.globalData.imgUrl,
    news: {},
    uploadUrl: wx.getStorageSync('uploadUrl'),
  },

  onLoad: function (options) {
    console.log(options,'options')
    this.setData({
      id: options.id,
      type: options.type      
    })   

    if (options.id){ 
      this.getDetail()
    }
    if (options.type=='view' ){
      this.viewfun()
    }
  },

  
  onUnload(){
    wx.removeStorageSync('cmsformdata')
  },

  //预览方法
  viewfun:function(){
    var data = wx.getStorageSync('cmsformdata') 
    this.setData({
      news: data,
      startDateText: data.startDate ? data.startDate.substring(0, 16) : '',
      expireDateText: data.expireDate ? data.expireDate.substring(0, 16) : '',
    })
    WxParse.wxParse('content', 'html', data.content, this, 25);
  },



  //获取商品详情
  getDetail: function () {
    _wxRequest.wxAjax({
      url: app.globalData.apiUrl + '/sys/info/getById?id=' + this.data.id,
      method: 'POST', 
    }, (res) => {
      console.log(res)
      this.setData({
        news: res,
        startDateText: res.startDate ? res.startDate.substring(0, 16) : '',
        expireDateText: res.expireDate ? res.expireDate.substring(0, 16) : '',
      })
      WxParse.wxParse('content', 'html', this.data.news.content, this, 25);
    })
  },


  toSto: function (e) {
    var id = e.currentTarget.dataset.id
    console.log(e)
    wx.navigateTo({
      url: '/pages/store/detail?id=' + id,
    })
  },





})